import Vue from "vue";
import {Tooltip} from "view-design";

//页面状态相关
let status = {
};

// 和网络交互相关的参数
let params = {
  searchParams:{
    date : "",
    isGetAll : false,
    orderKey : "",
    orderType : ""
  }
};

// 页面的数据源
let data = {
  userDailyList: [],
};

// 页码相关
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 60,
  currentPage: 1
};

//列表
let userDailyTable=function (self) {
  let table = [
    {
      type: 'index',
      title: '#',
      width: 70,
      key: 'index',
      fixed: 'left',
      align: 'center',
    },
    {
      title: '用户名',
      width: 160,
      key: 'userName',
      align:'center',
      render: (h, params) => {
        let hideName = Vue.prototype.$tiyHideUsername(params.row.userName);
        return h('span',hideName)
      }
    },
    {
      title: '注册时间',
      width: 130,
      key: 'registertime',
      render: (h, params) => {
        let date = new Date(params.row.registertime);
        return h('div', self.$tiyBJTime(params.row.registertime));
      },
      sortable: 'custom'
    },
    {
      title: '登录次数',
      width: 115,
      key: 'loginNumber',
      align:'center',
      sortable: 'custom'
    },
    {
      title: '加购次数',
      width: 115,
      key: 'addCartNumber',
      align:'center',
      sortable: 'custom'
    },
    {
      title: '付款订单数',
      width: 130,
      key: 'paidOrderNumber',
      align:'center',
      sortable: 'custom'
  },
  {
    title: '未付款订单数',
    width: 145,
    key: 'unpaidOrderNumber',
    align:'center',
    sortable: 'custom'
  },
  {
    title: '购物车总金额',
    width: 145,
    key: 'cartAmount',
    align:'center',
    sortable: 'custom'
  },
  !self.$authority('ANALYSIS-6-201')?null:{
    title: '来源',
    width: 120,
    key: 'source',
    align:'center'
  },
  !self.$authority('ANALYSIS-6-201')?null:{
    title: '邀请码',
    width: 120,
    key: 'inviteCode',
    align:'center'
  },
  !self.$authority('ANALYSIS-6-201')?null:{
    title: '补充邀请码',
    width: 120,
    key: 'externalInviteCode',
    align:'center'
  },
  !self.$authority('ANALYSIS-6-201')?null:{
    title: '分配码',
    width: 120,
    key: 'assign',
    align:'center'
  },
  !self.$authority('ANALYSIS-6-201')?null:{
    title: '邮箱',
    width: 160,
    key: 'email',
    align:'center',
    render: (h, params) => {
      let hideEmail = Vue.prototype.$tiyHideUsername(params.row.email);
      return(
        <div>
          <Tooltip content={params.row.email} placement="top">{hideEmail}</Tooltip>
        </div>
      );
    }
  },
  !self.$authority('ANALYSIS-6-201')?null:{
    title: '独立站',
    width: 100,
    key: 'contactUrl',
    align:'center',
    render: (h, params) => {
      let externalUrl = params.row.contactUrl;
      if (!externalUrl){
        return (
          <div><span></span></div>
        );
      }else{
        return (
          <div>
            <a target='_blank' href={externalUrl}>访问</a>
          </div>
        );
      }
    }
  },
  !self.$authority('ANALYSIS-6-201')?null:{
    title: 'Instagram',
    width: 120,
    key: 'instagram',
    align:'center',
    render: (h, params) => {
      let hideContent = Vue.prototype.$tiyHideUsername(params.row.instagram);
      return(
        <div>
          <Tooltip content={params.row.instagram} placement="top">{hideContent}</Tooltip>
        </div>
      );
    }
  },
  !self.$authority('ANALYSIS-6-201')?null:{
    title: 'Facebook',
    width: 120,
    key: 'facebook',
    align:'center',
    render: (h, params) => {
      let hideContent = Vue.prototype.$tiyHideUsername(params.row.facebook);
      return(
        <div>
          <Tooltip content={params.row.facebook} placement="top">{hideContent}</Tooltip>
        </div>
      );
    }
  }
  ];
  return self.$authTableTitles(table);
};

export  default  {
  tStatus: status,
  tParams: params,
  tData: data,
  tPage: page,
  userDailyTable:userDailyTable,
};
